<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    html,
    body {
      width: 100%;
      height: 100%;
      overflow: hidden;
    }
    .canvas-box {
      display: flex;
    }
    .cvs1,.cvs2{
      border: 1px solid #ccc;
      margin: 0 20px;
    }
  </style>
</head>

<body>
  <!-- <div class="canvas-box">
    <canvas class="cvs1" width="500" height="500"></canvas>
    <canvas class="cvs2" width="500" height="500"></canvas>
  </div> -->
  <script type="module">
    import * as THREE from "../node_modules/three/build/three.module.js"
    // 创建场景
    const scane = new THREE.Scene()

    // scane.background = new THREE.Color(0xc89e06b)
    const loader = new THREE.TextureLoader();
    // 异步
    loader.load("../image/Snipaste_2024-03-22_17-00-18.png", function (texture) {
      scane.background = texture;
      // renderer.render(scane, camera)
    })

    // 创建相机
    const camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000)
    camera.position.set(0, 4, 10)
    // camera.position.x = 2;
    camera.lookAt(0, 0, 0);
    // 创建渲染器
    const renderer = new THREE.WebGLRenderer({
      // canvas:document.querySelector(".cvs1")
    });
    renderer.setSize(window.innerWidth, window.innerHeight);
    document.body.appendChild(renderer.domElement);

    const cube = new THREE.Mesh(
      new THREE.BoxGeometry(1, 1, 1),
      new THREE.MeshBasicMaterial()
    )

    const cube2 = new THREE.Mesh(
      new THREE.BoxGeometry(1, 1, 1),
      new THREE.MeshBasicMaterial({
        color: 0xff0000
      })
    )
    cube2.position.x = 2

    scane.add(cube, cube2);

    let angle = 0;
    function animate() {
      requestAnimationFrame(animate)
      // cube.rotation.x += 0.01;
      // cube.rotation.y += 0.01;
      // angle += 0.01
      // const radius = 3
      // camera.position.x = radius * Math.cos(angle)
      // camera.position.z = radius * Math.sin(angle)
      renderer.render(scane, camera)
      camera.lookAt(0, 0, 0);
    }
    animate()

    renderer.render(scane, camera)
  </script>
</body>

</html>